<?php

namespace App\Admin\Controllers;

use \App\Models\Baoming;

use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Layout\Content;
use App\Http\Controllers\Controller;
use Encore\Admin\Controllers\AdminController;

class BaomingController extends Controller
{
    use AdminController;

    /**
     * Index interface.
     *
     * @return Content
     */
    public function index()
    {
        return Admin::content(function (Content $content) {

            $content->header('报名管理');
            $content->description('');

            $content->body($this->grid());
        });
    }

    /**
     * Edit interface.
     *
     * @param $id
     * @return Content
     */
    public function edit($id)
    {
        return Admin::content(function (Content $content) use ($id) {

            $content->header('报名管理');
            $content->description('');

            $content->body($this->form()->edit($id));
        });
    }

    /**
     * Create interface.
     *
     * @return Content
     */
    public function create()
    {
        return Admin::content(function (Content $content) {

            $content->header('报名管理');
            $content->description('');

            $content->body($this->form());
        });
    }

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Admin::grid(Baoming::class, function (Grid $grid) {

            $grid->id('ID')->sortable();

            $grid->column('relname', '联系人姓名');

            $grid->column('type', '报名类型')->value(function ($val) {

                if ($val == 1) {
                    return '<span class="badge bg-red">个人</span>';
                } else {
                    return '<span class="badge bg-green">组合</span>';
                }

            });

            $grid->created_at();

        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Admin::form(Baoming::class, function (Form $form) {

            $form->display('id', 'ID');

            $form->radio('type', '报名类型')->values(['1' => '个人', '2' => '组合'])->default('1');
            $form->text('relname', '参赛人1')->rules('required');
            $form->radio('sex', '性别1')->values(['1' => '男', '0' => '女'])->default('男');
            $form->text('age', '年龄1')->rules('required');

            $form->text('yueqi', '乐器1');
            $form->divide();

            $form->text('relname2', '参赛人2');
            $form->radio('sex2', '性别2')->values(['1' => '男', '0' => '女'])->default('男');
            $form->text('age2', '年龄2');
            $form->text('yueqi2', '乐器2');
            $form->divide();

            $form->text('song', '报名歌曲')->rules('required');

            $form->radio('yuanchuang', '原创')->values(['1' => '原创', '0' => '非原创'])->default('1');
            $form->url('video', '作品视频');
            $form->email('email', 'EMAIL')->rules('email');
            $form->text('mobile', '联系方式')->rules('required');

            $form->display('created_at', 'Created At');
            $form->display('updated_at', 'Updated At');
        });
    }
}
